<template>
  <div class="income_pay_button">
    <div class="header_type">
      <span :class="{'type_item': true, 'type_item_select': moneyTypeIndex === 'pay'}" @click="handleSelectMoneyType('pay')">支出</span>
      <span :class="{'type_item': true, 'type_item_select': moneyTypeIndex === 'income'}" @click="handleSelectMoneyType('income')">收入</span>
      <span :class="{'type_item': true, 'type_item_select': moneyTypeIndex === 'more'}" @click="handleSelectMoneyType('more')" v-if="more">结余</span>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
export default defineComponent({
  props: {
    more: {
      type: Boolean,
      default: false
    }
  },
  setup(props, context) {
    const moneyTypeIndex = ref('pay')
    const handleSelectMoneyType = (type: string) => {
      moneyTypeIndex.value = type
      context.emit('select', moneyTypeIndex.value)
    }
    return {
      moneyTypeIndex,
      handleSelectMoneyType
    }
  }
})
</script>

<style scoped>
  .header_type {
    border: #F9C3C2 1px solid;
    border-radius: 10px;
    font-size: 14px;
    overflow: hidden;
  }
  .type_item {
    padding: 4px 8px;
  }
  .type_item_select {
    background-color: #F9C3C2;
    border-radius: 10px;
  }
</style>